using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sundstrom.Mvvm.Command;

namespace Sundstrom.Mvvm.Tests
{
    [TestClass]
    public class RelayCommandTests
    {
        [TestMethod]
        public void NonGeneric_PlainExecute()
        {
            bool flag = false;

            var command = new RelayCommand(() => { flag = true; });

            command.Execute(null);

            Assert.IsTrue(flag);
        }

        [TestMethod]
        public void Generic_PlainExecute()
        {
            int flag = 0;

            var command = new RelayCommand<int>((x) => { flag = x; });

            command.Execute(2);

            Assert.IsTrue(flag == 2);
        }

        [TestMethod]
        public void NonGeneric_CanExecute()
        {
            bool flag = false;

            var command = new RelayCommand(() => { flag = true; }, () => true);

            Assert.IsTrue(command.CanExecute(null));
        }

        [TestMethod]
        public void NonGeneric_CannotExecute()
        {
            bool flag = false;

            var command = new RelayCommand(() => { flag = true; }, () => false);

            Assert.IsFalse(command.CanExecute(null));
        }

        [TestMethod]
        public void Generic_CanExecute()
        {
            bool flag = false;

            var command = new RelayCommand<int>((x) => { flag = true; }, (x) => x == 2);

            Assert.IsTrue(command.CanExecute(2));
        }

        [TestMethod]
        public void Generic_CannotExecute()
        {
            int flag = 0;

            var command = new RelayCommand<int>((x) => { flag = x; }, (x) => x == 2);

         
            Assert.IsFalse(command.CanExecute(3));
            command.Execute(3);
            Assert.IsTrue(flag == 3);
        }
    }
}